package com.ch.mapdemo.util;
/**
 * 判断点是否再圆内
 * @author ch
 *
 */
public class CircleDemo {

	public static void main(String[] args) {
				
		System.err.println("*****************************************");
		System.err.println(isInCircle(126.948594,44.411029,126.948824,44.411059,"18.18846220493293"));
		System.err.println(isInCircle(126.948594,44.411029,126.948266,44.410921,"18.18846220493293"));
		System.err.println(isInCircle(126.948594,44.411029,126.948937,44.410883,"18.18846220493293"));
		System.err.println(isInCircle(126.948594,44.411029,126.948572,44.410906,"18.18846220493293"));
//		System.err.println(isInCircle(126.948374,44.410824,126.948733,44.410712,"24.400881143166153"));
//		System.err.println(isInCircle(126.948374,44.410824,126.948583,44.410594,"24.400881143166153"));
//		System.err.println(isInCircle(126.948374,44.410824,126.948535,44.410624,"24.400881143166153"));
//		System.err.println(isInCircle(126.948374,44.410824,126.948245,44.410697,"24.400881143166153"));
//		System.err.println(isInCircle(126.948374,44.410824,126.948186,44.410843,"24.400881143166153"));
//		System.err.println(isInCircle(126.948374,44.410824,126.947993,44.410858,"24.400881143166153"));
		System.err.println("*****************************************");
		
		

	}
	
	
 
    /**
     * 通过经纬度获取距离(单位：米)
     *
     * @param lat1
     * @param lng1
     * @param lat2
     * @param lng2
     * @return
     */
    public static double getDistance(double lat1, double lng1, double lat2,
                                     double lng2) {
    	double R = 6378137; //地球半径
    	lat1 = lat1 * Math.PI / 180.0;
    	lat2 = lat2 * Math.PI / 180.0;
    	double sa2 = Math.sin((lat1 - lat2) / 2.0);
    	double sb2 = Math.sin(((lng1 - lng2) * Math.PI / 180.0) / 2.0);
    	return 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
    }
 
    /**
     * 判断一个点是否在圆形区域内  true为圆外 false 为圆内
     */
    public static boolean isInCircle(double lng1, double lat1, double lng2, double lat2, String radius) {
        return getDistance(lat1, lng1, lat2, lng2) > Double.parseDouble(radius);
    }

}
